package main

import "fmt"

type Observer interface {
	update(string)
}

type Subject struct {
	observers []Observer
}

func (s *Subject) attach(o Observer) {
	s.observers = append(s.observers, o)
}

func (s *Subject) notify(msg string) {
	for _, o := range s.observers {
		o.update(msg)
	}
}

type ConcreteObserver struct {
	name string
}

func (o *ConcreteObserver) update(msg string) {
	fmt.Printf("%s received: %s\n", o.name, msg)
}

func main() {
	subject := &Subject{}
	observer1 := &ConcreteObserver{name: "Observer 1"}
	observer2 := &ConcreteObserver{name: "Observer 2"}

	subject.attach(observer1)
	subject.attach(observer2)

	subject.notify("Hello, observers!")
	// Output:
	// Observer 1 received: Hello, observers!
	// Observer 2 received: Hello, observers!
}
